var gulp = require('gulp');
var through = require('through2');

gulp.task("build-index", function() {
    gulp.src("./views/weixin/*.ejs")
        .pipe(through.obj(function(file, encode, cb) {
            var contents = file.contents.toString(encode);

            var HTMLMinifier = require("html-minifier").minify;

            var minified = HTMLMinifier(contents, {
                minifyCSS: true,
                minifyJS: true,
                collapseWhitespace: true,
                removeAttributeQuotes: true
            });

            //console.log(minified);
            file.contents = new Buffer(minified, encode);
            cb(null, file, encode);
        }))
        .pipe(gulp.dest("./dist"));
});
